from playwright.sync_api import Playwright, sync_playwright, expect


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://www.jd.com/")
    page.get_by_role("link", name="你好，请登录").click()
    page.get_by_text("密码登录").click()
    page.locator("#formlogin div").filter(has_text="登 录").first.click()
    with page.expect_popup() as popup_info:
        page.get_by_role("link", name="立即注册").click()
    page1 = popup_info.value
    page1.close()
    page.get_by_placeholder("账号名/手机号/邮箱").click()
    page.get_by_placeholder("账号名/手机号/邮箱").fill("123123")
    page.get_by_placeholder("密码").click()
    page.get_by_placeholder("密码").fill("123412341234")
    page.get_by_role("link", name="登 录").click()
    page.locator("#JDJRV-wrap-loginsubmit a").first.click()

    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)
